<template>
  <div class="recruit">
    <!-- Header Banner -->
    <div class="banner" :style="{ backgroundImage: 'url(' + recruitData.section1.thumbnail + ')', backgroundSize: 'cover', backgroundPosition: 'center', backgroundRepeat: 'no-repeat' }">
      <h1>採用情報</h1>
    </div>
  </div>

  <!-- Overview Section -->
  <section class="overview">
    <h2 v-html="recruitData.section1.title"></h2>
    <dl>
      <template v-for="(item, index) in recruitList" :key="index">
      <div class="profile-row">
        <dt>{{ item.label }}：</dt>  <!-- コロンを追加 -->
        <dd v-html="item.value"></dd>
      </div>
    </template>
    </dl>
  </section>

  <!-- Application Section -->
  <section class="apply-box">
    <div v-html="recruitData.section2.content.replace(/&lt;br&gt;/g, '<br>')"></div>
    <!-- <div class="apply-row" >
      <strong class="apply-label">応募方法：</strong>
      <span class="apply-desc"
        >履歴書と職務経歴書をメール、または郵送にてお送り下さい。<br />書類選考を経て面接、内定という流れになります。</span
      >
    </div>
    <div class="apply-row">
      <strong class="apply-label">応募先メールアドレス：</strong>
      <div class="apply-desc">
        人事担当 山田 千秋 宛<br />
        <span class="email">yamada@sakura-pharma.com</span>
      </div>
    </div> -->
  </section>
</template>

<script>
import { getRecruitData } from "@/api";

export default {
  name: "RecruitPage",
  data() {
    return {
      recruitData: {
        section1: {
          title: "",
          thumbnail: "",
          subtitle: "",
          content: "",
        },
        section2: {
          title: "",
          thumbnail: "",
          subtitle: "",
          content: "",
        }
      },
    };
  },
  computed: {
    recruitList() {
      const html = this.recruitData.section1.content || '';
      const tempDiv = document.createElement('div');
      tempDiv.innerHTML = html;

      const items = [];
      const children = Array.from(tempDiv.children);
      let currentLabel = '';
      children.forEach(p => {
        const text = p.innerText.replace(/\n/g, '').trim();
        const parts = text.split('：');
        if (parts.length === 2) {
          currentLabel = parts[0].trim();
          items.push({ label: currentLabel, value: parts[1].trim() });
        } else if (parts.length === 1 && currentLabel) {
          const last = items[items.length - 1];
          last.value += `${parts[0].trim()}`;
        }
      });
      return items;
    }
  },
  async mounted() {
    try {
      const data = await getRecruitData();
      this.recruitData = {
        section1: {
          ...data.rows[0],
          content: data.rows[0].content.replace(/&lt;br&gt;/g, "<br>"),
        },
        section2: {
          ...data.rows[1],
          content: data.rows[1].content.replace(/&lt;br&gt;/g, "<br>"),
        },
      };
    } catch (error) {
      console.error("Error fetching recruit data:", error);
    }
  },
};
</script>

<style scoped>
.recruit {
  font-family: "Noto Sans JP", sans-serif;
  color: #333;
  background: #fff;
}
.banner {
 
  text-align: center;
  padding: 60px 0;
  color: #8d6e52;
}

.banner h1 {
  text-align: center;
  font-size: 36px;
  margin: 40px 0;
  font-family: "Hiragino Sans", "Noto Sans JP", sans-serif; /* 添加黑体字体 */
  font-weight: 400; /* 取消加粗 */
  color: #666;
}

.banner p {
  font-size: 18px;
}
.overview,
.daily-flow,
.apply-box {
  max-width: 900px;
  margin: 60px auto;
  padding: 0 1.5rem;
}
.overview h2,
.daily-flow h2 {
  font-size: 1.9rem;
  margin-bottom: 25px;
  font-family: "HiraMinProN-W3", "Hiragino Mincho Pro", serif;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: #2a2a2a;
  position: relative;
  padding-bottom: 15px;
  text-align: center;
}

.overview h2::after,
.daily-flow h2::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 46%;
  width: 50px;
  height: 2px;
  background: linear-gradient(90deg, #f8d7a3, #f5b8ca);
}

.overview dl > div {
  display: flex;
  margin-bottom: 15px;
  align-items: flex-start;
}

.overview dl > div > dt {
  font-weight: bold;
  width: 180px; /* 固定宽度 */
  flex-shrink: 0;
  color: #666;
}

.overview dl > div > dd {
  margin: 0;
  color: #555;
  flex-grow: 1;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 20px;
  text-align: center;
}
.flow-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 10px;
}
.time {
  background: #f3f0ea;
  color: #a1875b;
  font-weight: bold;
  padding: 5px;
  border-radius: 4px;
}

/* 修改apply-box内部样式 */
.apply-box {
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 20px;
  background: #fefefe;
  margin-bottom: 60px;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.apply-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    135deg,
    rgba(248, 215, 163, 0.1) 0%,
    rgba(245, 184, 202, 0.1) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease;
}

.apply-box:hover::before {
  opacity: 1;
}

.apply-box:active {
  transform: scale(0.98);
}

.apply-row {
  display: flex;
  margin-bottom: 15px;
  align-items: baseline;
}

.apply-label {
  min-width: 180px; /* 最小幅を設定 */
  flex-shrink: 0;
  font-weight: bold;
  color: #666;
}

.apply-desc {
  flex-grow: 1;
  color: #666;
  white-space: normal; /* 确保可以换行 */
}
.apply-box:hover {
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15); /* 鼠标悬停时阴影加深 */
  transform: translateY(-2px); /* 轻微上浮效果 */
}

.apply-label {
  width: auto; /* 改为自动宽度 */
  flex-shrink: 0;
  color: #666; /* 字体颜色 */
}

.apply-desc {
  flex-grow: 0; /* 取消自动扩展 */
  color: #666; /* 字体颜色 */
}
.apply-box .email {
  color: #a03b3b;
  font-weight: bold;
}

.desc strong {
  font-size: 18px;
  display: block;
  margin-bottom: 5px;
}

.desc p {
  font-size: 16px;
  color: #555;
}

@media (max-width: 768px) {
  .overview dl > div {
    flex-direction: column;
    margin-bottom: 20px;
  }

  .overview dl > div > dt {
    width: 100%;
    margin-bottom: 5px;
  }

  .overview dl > div > dd {
    width: 100%;
  }

  .apply-row {
    flex-direction: column;
  }

  .apply-label {
    width: 100%;
    margin-bottom: 5px;
  }

  .apply-desc {
    width: 100%;
  }
}
</style>
